home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / The Weakest Link / source / OpenTptEnet / CIncludes / EnetUser.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  10.0 KB  |  320 lines

  1. /*
  2.     File:        EnetUser.h
  3.  
  4.     Contains:    EnetUser includes
  5.  
  6.     Version:    1.0.0
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12.  
  13. #ifndef __ENETUSER_H__
  14. #define __ENETUSER_H__
  15.  
  16. /******************************************************************************/
  17.  
  18. // The default MACOS is ON, MACH3 is OFF.
  19. #ifndef MACOS
  20. #define MACOS 1
  21. #define MACH3 0
  22. #endif
  23.  
  24. /******************************************************************************/
  25.  
  26. #if MACOS
  27.  
  28. #ifdef __ENETLIB_H__
  29. #define OTKERNEL 1
  30. #endif
  31.  
  32. #include "dlpiuser.h"
  33.  
  34. #include <dlpi.h>
  35. #include <Resources.h>
  36.  
  37. // This should be in OpenTransport.h
  38. enum {
  39.     MIOC_ENET        = 'E'        /* ioctl's for Apple Enet */
  40. };
  41.  
  42. // This should be in dlpiuser.h
  43. #define kMaxEnetStatus        16384
  44. #define IOC_ENETSTATUS        MIOC_CMD(MIOC_ENET, 1)    // retrieve status information
  45. #define IOC_ENETTEST        MIOC_CMD(MIOC_ENET, 2)    // run test and retrieve log and status
  46. #define IOC_ENETRESET        MIOC_CMD(MIOC_ENET, 3)    // reset and retrieve log and status
  47. #define IOC_ENETLOG            MIOC_CMD(MIOC_ENET, 4)    // retrieve log information
  48. #define IOC_DLPITEST        MIOC_CMD(MIOC_ENET, 5)
  49. #define IOC_DLPITEST_RESET            0x00000000        // reset to normal operation
  50. #define IOC_DLPITEST_TX_BLOCK        0x00000001        // block transmitter
  51. #define IOC_DLPITEST_TX_UNBLOCK        0x00000002        // unblock transmitter
  52. #define IOC_DLPITEST_PROMISCUOUS    0x00000003        // disable external address filter
  53. #define IOC_DLPITEST_FILTER            0x00000004        // enable external address filter
  54. #define IOC_DLPITEST_INTERNAL        0x00000005        // disable external network access
  55. #define IOC_DLPITEST_EXTERNAL        0x00000006        // enable external network access
  56. #ifdef MIOC_ND
  57. #define ND_GET                MIOC_CMD(MIOC_ND, 0)
  58. #define ND_SET                MIOC_CMD(MIOC_ND, 1)
  59. #else
  60. #define ND_GET                MIOC_CMD(MIOC_ENET, 6)
  61. #define ND_SET                MIOC_CMD(MIOC_ENET, 7)
  62. #endif
  63.  
  64. // This should be in dlpiuser.h
  65. enum {
  66.     DL_NO_ERROR                = 0x00,
  67.     DL_MAC_ERROR            = 0x08
  68. };
  69.  
  70. // Enet Virtual Controller for support of Mac and PC clients
  71.  
  72. #define I_VirtualControllerIoctl 6001
  73.  
  74. enum VirtualControllerOptions {
  75.     kVCCreateController            = 0x00000001,
  76.     kVCAssignController            = 0x00000002,
  77.     kVCEnableStandardMode        = 0x00000004,
  78.     kVCEnablePaddingMode        = 0x00000008,
  79.     kVCEnableCRCMode            = 0x00000010,
  80.     kVCEnablePromiscuousMode    = 0x00000020
  81. };
  82.  
  83. typedef struct VCRequest VCRequest;
  84. typedef VCRequest *VCRequestPtr;
  85. struct VCRequest {
  86.     UInt16                        vcOptions;            
  87.     UInt16                        vcID;            
  88. };
  89.  
  90. // ENETShim mode for supporting .enet driver on PCI machines
  91.  
  92. #define kOTENETShimIoctl        6000
  93.  
  94. enum ENETtoDLPICommands {
  95.     kSetEthernetAddress            = 1,
  96.     kSNMPDot3Entry                = 2,
  97.     kSNMPDot3Stats                = 3,
  98.     kSNMPLapMIBStats            = 4,
  99.     kENETShimAddQTCHack            = 10,
  100.     kENETShimDeleteQTCHack        = 11,
  101.     kSetENETShimStreamType        = 12,
  102.     kSetENETShimPromiscOn        = 13,
  103.     kSetENETShimPromiscOff        = 14
  104. };
  105.  
  106. typedef struct ENETShimRequest ENETShimRequest;
  107. typedef ENETShimRequest *ENETShimRequestPtr;
  108. struct ENETShimRequest {
  109.     UInt16                        enetCommand;            
  110.     UInt16                        enetSize;            
  111.     void *                        enetAddress;
  112. };
  113.  
  114. //#include <SNMPLAP.h>
  115.  
  116. struct Dot3Entry {
  117.     unsigned long    dot3Version;                /* Version of LapDot3 entry that we support */
  118.     unsigned long    dot3Index;                    /* ifIndex for this driver */
  119.     unsigned long    dot3InitializeMac;            /* Init status (1 = inited, 2 = uninited) */
  120.     unsigned long    dot3MacSubLayerStatus;        /* Op status of the MAC sublayer (1 = enabled, 2 = disabled) */
  121.     unsigned long    dot3MulticastReceiveStatus;    /* Multicast receive status (1 = enabled, 2 = disabled) */
  122.     unsigned long    dot3TxEnabled;                /* MAC frame tx state (1 = enabled, 2 = disabled) */
  123.     unsigned long    dot3TestTdrValue;            /* Time between TDR start/end */
  124. };
  125. typedef struct Dot3Entry Dot3Entry;
  126.  
  127. #define SNMPVersion        0x100                    /* used for LAPMIBStats, Dot3Stats, Dot3Entry */
  128.  
  129. // dot3InitializeMac
  130. enum {
  131.     dot3initialized                = 1,
  132.     dot3uninitialized            = 2
  133. };
  134.  
  135. // dot3SubLayerStatus, dot3MulticastReceiveStatus
  136. enum {
  137.     dot3enabled                    = 1,
  138.     dot3disabled                = 2
  139. };
  140.  
  141. // dot3TxEnabled, dot5ActMonParticipate
  142. enum {
  143.     dot_true                    = 1,
  144.     dot_false                    = 2
  145. };
  146.  
  147. struct Dot3StatsEntry {
  148.     unsigned long    dot3StatsVersion;            /* Version number */
  149.     unsigned long    dot3StatsIndex;                /* Same as ifIndex (to be left at zero) */
  150.     unsigned long    dot3StatsAlignmentErrors;
  151.     unsigned long    dot3StatsFCSErrors;
  152.     unsigned long    dot3StatsSingleCollisionFrames;
  153.     unsigned long    dot3StatsMultipleCollisionFrames;
  154.     unsigned long    dot3StatsSQETestErrors;
  155.     unsigned long    dot3StatsDeferredTransmissions;
  156.     unsigned long    dot3StatsLateCollisions;
  157.     unsigned long    dot3StatsExcessiveCollisions;
  158.     unsigned long    dot3StatsInternalMacTransmitErrors;
  159.     unsigned long    dot3StatsCarrierSenseErrors;
  160.     unsigned long    dot3StatsExcessiveDeferrals;
  161.     unsigned long    dot3StatsFrameTooLongs;
  162.     unsigned long    dot3StatsInRangeLengthErrors;
  163.     unsigned long    dot3StatsOutOfRangeLengthFields;
  164.     unsigned long    dot3StatsInternalMacReceiveErrors;
  165. };
  166. typedef struct Dot3StatsEntry Dot3StatsEntry;
  167.  
  168. struct LAPMIBStats {
  169.     unsigned long    ifVersion;            /* Version of LinkStats we support */
  170.     Str255            ifDescr;            /* String with info about interface */
  171.     unsigned long    ifType;                /* Code with type of interface */
  172.     unsigned long    ifMaxMTU;            /* Largest size of IP datagram that can be tx/recv */
  173.     unsigned long    ifSpeed;            /* Bandwidth in bits/second */
  174.     Str31            ifPhysAddress;        /* Interface address */
  175.     unsigned long    ifAdminStatus;        /* Desired state (1 = up, 2 = down, 3 = testing) */
  176.     unsigned long    ifOperStatus;        /* Current state (1 = up, 2 = down, 3 = testing) */
  177.     unsigned long    ifLastChange;        /* SysTicks when interface entered current operation state */
  178.     unsigned long    ifInOctets;            /* Total nbr bytes received including framing chars*/
  179.     unsigned long    ifInUcastPkts;        /* Nbr of unicast packets received */
  180.     unsigned long    ifInNUcastPkts;        /* Nbr of broad/multi cast packets received */
  181.     unsigned long    ifInDiscards;        /* Nbr of overwrites that occured */
  182.     unsigned long    ifInErrors;            /* Nbr of pkts recv which contain error */
  183.     unsigned long    ifInUnknownProtos;    /* Nbr of pkts recv discarded cuz of unknown protocol */
  184.     unsigned long    ifOutOctets;        /* Total nbr bytes tx including framing chars */
  185.     unsigned long    ifOutUcastPkts;        /* Nbr of unicast packets tx */
  186.     unsigned long    ifOutNUcastPkts;    /* Nbr of broad/multi cast packets tx */
  187.     unsigned long    ifOutDiscards;        /* Nbr tx pkts discarded */
  188.     unsigned long    ifOutErrors;        /* Nbr tx pkts not sent due to error */
  189.     unsigned long    ifOutQLen;            /* Current nbr of packets in output queue */
  190. };
  191. typedef struct LAPMIBStats LAPMIBStats;
  192.  
  193. // ifAdminStatus and ifOperStatus
  194. enum {
  195.     ifStatusUp            =        1,
  196.     ifStatusDown        =        2,
  197.     ifStatusTesting        =        3
  198. };
  199.  
  200. // IfTypes
  201. enum {
  202.     other                 =        1,        /* none of the following */
  203.     regular1822            =        2,
  204.     hdh1822                =        3,
  205.     ddn_x25             =        4,
  206.     rfc877_x25             =        5,
  207.     ethernet_csmacd        =        6,
  208.     iso88023_csmacd     =        7,
  209.     iso88024_tokenBus    =        8,
  210.     iso88025_tokenRing     =        9,
  211.     iso88026_man         =        10,
  212.     starLan                =        11,
  213.     proteon_10Mbit         =        12,
  214.     proteon_80Mbit        =        13,
  215.     hyperchannel         =        14,
  216.     fddi                =        15,
  217.     lapb                 =        16,
  218.     sdlc                =        17,
  219.     ds1                    =        18,        /* T-1 */
  220.     e1                    =        19,     /* european equivalent of T-1 */
  221.     basicISDN             =        20,
  222.     primaryISDN         =        21,
  223.     propPointToPointSerial =    22,        /* proprietary serial */
  224.     ppp                    =        23,
  225.     softwareLoopback    =        24,
  226.     eon                    =        25,        /* CLNP over IP */
  227.     ethernet_3Mbit        =        26,
  228.     nsip                =        27,        /* XMS over IP */
  229.     slip                =        28,        /* generic SLIP */
  230.     ultra                =        29,        /* ULTRA technologie */
  231.     ds3                    =        30,        /* T-3 */
  232.     sip                    =        31,        /* SMDS */
  233.     frame_relay            =        32
  234. };
  235.  
  236. #endif // MACOS
  237.  
  238. #if MACH3
  239. #endif // MACH3
  240.  
  241. // Where should these be?
  242. #define    kTestProto            0x809B    
  243. #define kEchoProto            0x809D
  244.  
  245. enum {
  246.     kEnetMaxTSDU            = 1514,
  247.     kEnetMinTSDU            = 14,
  248.     kEnetMaxRSDU            = kEnetMaxTSDU + sizeof(UInt32),
  249.     kEnetMinRSDU            = kEnetMinTSDU + sizeof(UInt32)
  250. };
  251.  
  252. typedef UInt8                EnetAddress[6];
  253. typedef UInt8 *                EnetAddressPtr;
  254.  
  255. typedef struct EnetHeader EnetHeader;
  256. typedef EnetHeader *EnetHeaderPtr;
  257. struct EnetHeader
  258. {
  259.     UInt8    fDestAddr[6];
  260.     UInt8    fSourceAddr[6];
  261.     UInt16    fProto;
  262. };
  263.  
  264. // CompareEnetAddress() compares two ethernet addresses.
  265. // Returns false if they are not equal.
  266. #define CompareEnetAddress(a1, a2)                            \
  267.     ((*(const UInt32*)((const UInt8*)(a1)) ==                \
  268.       *(const UInt32*)((const UInt8*)(a2))) &&                \
  269.      (*(const UInt16*)(((const UInt8*)(a1))+4) ==            \
  270.       *(const UInt16*)(((const UInt8*)(a2))+4)))
  271.  
  272. // CopyEnetAddress() copies an ethernet address. 
  273. #define CopyEnetAddress(s, d)                                \
  274.     (*(UInt32*)((UInt8*)(d)) =                                \
  275.      *(const UInt32*)((const UInt8*)(s)),                    \
  276.      *(UInt16*)(((UInt8*)(d))+4) =                            \
  277.      *(const UInt16*)(((const UInt8*)(s))+4) )
  278.  
  279. // IsEnetAddressMulticast() checks for a multicast address.
  280. // Returns false if the specified address is not a multicast address.
  281. #define IsEnetAddressMulticast(a)                            \
  282.     (((const UInt8*)(a))[0] & 0x01)
  283.  
  284. // IsEnetAddressBroadcast() checks for a broadcast address.
  285. // Returns false if the specified address is not a broadcast address.
  286. #define IsEnetAddressBroadcast(a)                            \
  287.     ((*(const UInt32*)((const UInt8*)(a)) == 0xFFFFFFFF) &&    \
  288.      (*(const UInt16*)(((const UInt8*)(a))+4) == 0xFFFF))
  289.  
  290. // SetBroadcastEnetAddress() sets a broadcast address value.
  291. #define SetBroadcastEnetAddress(a)                            \
  292.     (*(UInt32*)((UInt8*)(a)) = 0xFFFFFFFF,                    \
  293.      *(UInt16*)(((UInt8*)(a))+4) = 0xFFFF )
  294.  
  295. // IsEnetAddressZero() checks for a zero address.
  296. // Returns false if the specified address is not zero.
  297. #define IsEnetAddressZero(a)                                \
  298.     (!*(const UInt32*)((const UInt8*)(a)) &&                 \
  299.      !*(const UInt16*)(((const UInt8*)(a))+4))
  300.  
  301. // IsEnetAddressZeroMisaligned() checks for a zero address.
  302. // Returns false if the specified address is not zero.
  303. // This variant of IsEnetAddressZero is specially for use with
  304. // the source address of an Ethernet packet, which starts at
  305. // the sixth byte of the packet (i.e. it is not long-word aligned).
  306. #define IsEnetAddressZeroMisaligned(a)                        \
  307.     (!*(const UInt16*)((const UInt8*)(a)) &&                 \
  308.      !*(const UInt32*)(((const UInt8*)(a))+2))
  309.  
  310. // SetEnetAddressZero() sets a zero address value.
  311. #define SetEnetAddressZero(a)                                \
  312.     (*(UInt32*)((UInt8*)(a)) = 0,                            \
  313.      *(UInt16*)(((UInt8*)(a))+4) = 0 )
  314.  
  315. #define IsValidUnicastAddress(a)                            \
  316.     (IsEnetAddressZero(a) ? 0 :                                \
  317.         (IsEnetAddressBroadcast(a) ? 0 :                    \
  318.             (IsEnetAddressMulticast(a) ? 0 : 1)))
  319. #endif // __ENETUSER_H__
  320.